/*
 * Copyright (C) 2018 Square, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { ProxySelector } from "../ProxySelector";
import { Proxy } from '../Socket/Proxy'
import { List, uri } from '@kit.ArkTS'
import { SocketAddress } from "../Socket/SocketAddress";
import { IllegalStateException } from "../Error/error";

/**
 * A proxy selector that always returns a direct connection (no proxy).
 * This is used when the OkHttpClient has a specific proxy configured,
 * or when no proxy should be used at all.
 */
export class NullProxySelectorClass extends ProxySelector {
  /**
   * Returns a list containing only the direct connection (NO_PROXY).
   * @param uri - The target URI (must not be null)
   * @returns A list with a single direct connection proxy
   * @throws Error if uri is null
   */
  select(uri?: uri.URI): List<Proxy> {
    if (uri === undefined) {
      throw new IllegalStateException("uri must not be null");
    }
    let list: List<Proxy> = new List<Proxy>();
    list.add(Proxy.NO_PROXY)
    return list;
  }

  /**
   * No-op implementation since this selector never provides proxies that can fail.
   */
  connectFailed(uri: uri.URI, sa: SocketAddress, error: Error): void {
    // No-op: We don't track failures for direct connections
  }
}

// 🔥 创建并导出单例实例（相当于 Kotlin 的 object）
export const NullProxySelector = new NullProxySelectorClass();